#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    vector<int> v1;
    int m = 0;
    int n = 0;
    cin >> m >> n;
    for (int i = 1; i <= m; i++) {
        v1.push_back(i);
    }
    int count = 0;
    vector<int>::iterator it = v1.begin();
    while (v1.size() > 1) {
        if (it == v1.end()) {
            it = v1.begin();
        }
        count++;
        if (count == n) {
            it = v1.erase(it);
            count = 0;
        }
        else {
            it++;
        }

    }
    cout << v1[0] << endl;
    return 0;
}

